importPackage(net.sf.odinms.net.channel);
importPackage(net.sf.odinms.client);
importPackage(net.sf.odinms.server.maps);
importPackage(net.sf.odinms.tools);

var status = 0;
var chicken = 0;
var weddingmap = 680000210;

function start() {
    status = -1;
    action(1, 0, 0);
}

function action(mode, type, selection) {
	if (mode == -1) {
        	cm.dispose();
	} else {
        	if (mode == 0 && status == 0) {
			cm.sendOk("Come back if you made up your mind");
        		cm.dispose();
        		return;
        	}
        	if (mode == 1)
        		status++;
        	else
        		status--;
        	if (status == 0) {
			if (cm.getChar().getMapId() == weddingmap) {
				if (cm.isMarry() == 1) {
					if (cm.getChar().getGender() == 0) {
						cm.sendOk("I will send you and your wife out of here in 1 minute");
						cm.mapMessage("[Priest] Today we are here to marry two joung people who are in love");
						cm.mapMessage("[Priest] With all the powers invested in me I now pronounce you husband and wife");
						cm.setPartyMarried();
						cm.getChar().getClient().getSession().write(net.sf.odinms.tools.MaplePacketCreator.getClock(60));
						cm.startPartyTimer(680000300, 60000);
						cm.dispose();
					} else {
						cm.sendOk("Please have your man talk to me\r\nand make sure that you are in a party with him");
					}
				} else if (cm.isGuest() == 1) {
					cm.sendOk("You don't have to talk with me");
					cm.dispose();
				} else {
					cm.sendOk("You came here bugged. please leave");
					cm.dispose();
				}
			} else {
			if (cm.isBlessed() == 0) {
				cm.sendOk("If you want to marry then please ask your parents to bless you");
				cm.dispose();
			} else {
				if (cm.isMarried() == 1) {
					cm.sendOk("You pervert! you are already married!");
					cm.dispose();
				} else {
					cm.sendSimple("#L1##bI want to get married#l\r\n#L2#I am invited to a wedding#k#l\r\n#L3##rLol nothing, you suck#k#l");
				}
			}
			}
		} else if (status == 1) {
			if (selection == 1) {
				if (cm.itemQuantity(5251003) > 0 || cm.itemQuantity(5251002) > 0 || cm.itemQuantity(5251001) > 0 || cm.itemQuantity(5251000) > 0) {
					cm.sendYesNo("Ah, you have a wedding ticket, want to get in now?");
					chicken = 1;
				} else {
					cm.sendOk("You don't have a wedding ticket, you can buy one in Cash Shop");
					cm.dispose();
				}
			} else if (selection == 2) {
				if (cm.getCharQuantity(weddingmap) > 0) {
					if (cm.itemQuantity(5251100) > 0) {
						cm.sendYesNo("Ah you have an invitation, wanna get in?\r\n#r#ePlease make sure you are in a party with only your husband/wife#k#n");
						chicken = 2;
					} else {
						cm.sendOk("You don't have an invitation, get away from here!");
						cm.dispose();
					}
				} else {
					cm.sendOk("There is no wedding going on yet");
					cm.dispose();
				}
			} else {
				cm.sendOk("Go away you little brat");
				cm.dispose();
			}
		} else if (status == 2) {
			if (chicken == 1) {
                		cm.warpWedding(0);
				if (cm.itemQuantity(5251003) > 0) {
					cm.gainItem(5251003, -1);
					cm.dispose();
				} else if (cm.itemQuantity(5251002) > 0) {
					cm.gainItem(5251002, -1);
					cm.dispose();
				} else if (cm.itemQuantity(5251001) > 0) {
					cm.gainItem(5251001, -1);
					cm.dispose();
				} else if (cm.itemQuantity(5251000) > 0) {
					cm.gainItem(5251000, -1);
					cm.dispose();
				} else {
					cm.dispose();
				}
			} else {
				cm.gainItem(5251100, -1);
				cm.warpWedding(1);
			}
		} else {
			cm.dispose();
		}
	}
}